<%--
  Created by IntelliJ IDEA.
  User: mi
  Date: 2018/9/29
  Time: 20:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="${basePath}/public/css/adminbase.css">
    <link href="${basePath}/public/js/webuploader.css" rel="stylesheet">
    <script type="text/javascript" src="${basePath}/public/js/jquery.min.js"></script>
    <script type="text/javascript" src="${basePath}/public/js/webuploader.min.js"></script>

    <script type="text/javascript">

        //初始化Web Uploader
        var uploader ;
        $(function(){

            uploader = WebUploader.create({
                // 选完文件后，是否自动上传。
                auto: true,
                // swf文件路径
                swf: '${pageContext.request.contextPath}/public/js/Uploader.swf',
                // 文件接收服务端。
                server:'${basePath}/admin/work/toFile',
                // 选择文件的按钮。可选。
                // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                pick: '#images',
                //设置文件上传域的name
                fileVal:"fileImg",

                //文件上传请求的参数表，每次发送都会发送此对象中的参数
                formData:{

                },
                // 只允许选择图片文件。
                accept: {
                    title: 'Images',
                    extensions: 'gif,jpg,jpeg,bmp,png',
                    mimeTypes: 'image/*'
                }
            });

            //上传图片完成后回调的方法
            uploader.on('uploadSuccess', function(file,response) {
                //服务器返回json数据
                console.info(response);
                //将上传的文件路径绑定在页面中
                $("#imageList").append("<img src='"+response.url+"' style='width:100px;height:100px;' />"
                    +"<input type='hidden' name='imgfile' value='"+response.url1+"'/>"
                );
            });

        });

        function button() {
            var newsTitle = $("#newsTitle").val();
            var countClick = $("#countClick").val();
            var commentCount = $("#commentCount").val();
            var subTitle = $("#subTitle").val();
            var addTime = $("#addTime").val();
            var description = $("#description").val();
            var catalogId = $("#catalogId").val();
            var isShow=$(":input[name='isShow']:checked").val();
            var newsImg = $(":input[name='imgfile']").val();
            $.ajax({
                url:"${basePath}/admin/news/add",
                type:"post",
                data:{
                    newsTitle:newsTitle,
                    countClick:countClick,
                    commentCount:commentCount,
                    subTitle:subTitle,
                    addTime:addTime,
                    description:description,
                    catalogId:catalogId,
                    isShow:isShow,
                    newsImg:newsImg

                },
                success:function (resultJson) {
                    if (resultJson.status==1){
                        window.location.href="${basePath}/admin/adminUser/work/index";
                    } else {
                        alert(resultJson.msg);
                    }
                }
            })
        }
    </script>
</head>
<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">修改</a></li>
    </ul>
</div>

<div class="session-main">
    <div class="formbody">

            <ul class="forminfo">
                <li><label>新闻标题</label><input name="" type="text" class="dfinput" value="" id="newsTitle"><i>名称不能超过30个字符</i></li>
                <li><label>简标题</label><input name="" type="text" class="dfinput" value="" id="subTitle"></li>
                <li>
                    <label>新闻略缩图</label>
                    <div id="imageList"></div>
                    <div id="images">添加图片</div>
                </li>
                <li><label>预览次数</label><input name="" type="text" class="dfinput" value="" id="countClick" ></li>
                <li><label>添加时间</label><input name="" type="text" class="dfinput" value="" id="addTime"/></li>
                <li><label>评论次数</label><input name="" type="text" class="dfinput" value="" id="commentCount"></li>
                <li><label>详细信息</label><input name="" type="text" class="dfinput" value="" id="description"></li>
                <li><label>新闻分类编号</label><input name="" type="text" class="dfinput" value="" id="catalogId"></li>

                <li><label>是否显示</label>
                <cite>
                    <input name="isShow" type="radio" value="1" checked="checked"  class="isShow">是&nbsp;&nbsp;&nbsp;&nbsp;
                    <input name="isShow" type="radio" value="0" class="isShow">否
                </cite>
            </li>
                <li>
                    <label>&nbsp;</label>
                    <input name="" type="button" class="btn" value="确认保存" onclick="button()">
                    <input type="button" class="btn" onclick="javascript:window.location.href='index.html'" value="返回" style=" background: #57e980;">
                </li>
            </ul>

    </div>

</div>

</body>
</html>
